package cn.his.medical.phismange

import android.graphics.Color
import android.os.Bundle
import android.support.v4.widget.DrawerLayout.LayoutParams
import android.widget.ImageView
import android.widget.LinearLayout
import cn.his.medical.phismange.adapter.MyAdapter
import cn.his.medical.phismange.app.base.BaseActivityKt
import cn.his.medical.phismange.bean.ViewPagerBean
import cn.his.medical.phismange.view.BannerView
import cn.his.medical.phismange.view.UpRoll


class MainActivity : BaseActivityKt() {
    lateinit var linearLayout: LinearLayout
    val dots = ArrayList<ImageView>()
    val list = ArrayList<String>()
    override fun getLayoutId(): Int = R.layout.activity_main;
    override fun initEventAndData() {
        linearLayout = findViewById(R.id.ll) as LinearLayout
//        val vp = findViewById(R.id.vp) as AutoViewPager

        val up_roll = findViewById<UpRoll>(R.id.up_roll)
        up_roll.textList = initList()
        up_roll.setTextColor(Color.BLACK);
        up_roll.setTextSize(20)
        up_roll.animMode = 1
        up_roll.startAutoScroll()
        val bannerView = findViewById<BannerView>(R.id.view_pager)
        bannerView.setBannerDuring(3000)
//        val myAdapter = ViewPagerAdapter(this,initdata());
//        vp.adapter = myAdapter
        val adapter1 = MyAdapter(initdata(), this)
        bannerView.setAdapter(adapter1)
        //初始化小圆点
        initDots()
        bannerView.setOnBannerChangeListener({
            for (i in 0..14) {
                if (i == it % 15) {
                    dots.get(i).setImageResource(R.drawable.dots_focus);
                }
                //否则换成灰色小圆点
                else {
                    dots.get(i).setImageResource(R.drawable.dots_normal);
                }
            }
        })
    }
    fun initList() : ArrayList<String>? {
        list.clear()
        for (i in 0..5) {
            list.add("阿斯加德好" + i.toString())
        }
        return list
    }
    fun initdata(): ArrayList<ViewPagerBean>? {
        var mDataSource = ArrayList<ViewPagerBean>()
        for (i in 0..14) {
            val bean = ViewPagerBean()
            bean.t_intro = getResources().getString(R.string.biography) + i
            bean.t_sub_head = "杀鸡风华绝代撒回复大法好" + i
            bean.t_user_name = "日龙包" + i
            bean.t_show_time = "20188年44月232日" + i
            bean.t_show_address = "月球上的山顶顶上的狗狗头" + i
            bean.t_show_phone = "678967890" + i
            mDataSource?.add(bean)
        }
        return mDataSource
    }

    fun initDots(): ArrayList<ImageView>? {
        dots.clear()
        linearLayout.removeAllViews()
        for (i in 0..14) {
            val view = ImageView(this)
            if (i == 0) {
                view.setImageResource(R.drawable.dots_focus)
            } else {
                view.setImageResource(R.drawable.dots_normal)
            }
            val params = LayoutParams(20, 20)
            //设置小圆点的边距
            params.setMargins(10, 0, 10, 0);
            //把小圆点添加到布局中
            linearLayout.addView(view, params);
            //把小圆点添加到集合
            dots.add(view);
        }
        return dots
    }

    override fun initEventAndData(savedInstanceState: Bundle) {
    }

}
